﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Starfire3d.Interfaces;
using Starfire3d.Data.States;
using Starfire3d.Data.States.UnitStates;
using Starfire3d.Data.Behaviours.Targeting;
using Starfire3d.Data.Objects;

namespace Starfire3d.Data
{
    public class Unit : GameObject, IRenderable
    {
        private ControlSheet details = null;
        private StateMachine<Unit> stateMachine = null;

        private ITargetingBehaviour targetingBehaviour = null;

        public ControlSheet Sheet
        {
            get { return details; }
            protected set { details = value; }
        }

        public ITargetingBehaviour Targeting
        {
            get { return targetingBehaviour; }
            set { targetingBehaviour = value; }
        }

        public StateMachine<Unit> StateMachine
        {
            get { return stateMachine; }
        }

        public bool IsDead
        {
            get { return Sheet.IsDestroyed; }
        }

        public Unit()
        {
            CreateDataStore();

            Sheet = (DataItemStore.GetStoreContents("ControlSheet")[0] as ControlSheet).Clone() as ControlSheet;
            Targeting = new TargetRandom();

            stateMachine = new StateMachine<Unit>(this);
            stateMachine.CurrentState = new IdleUnit();
        }

        public override bool Update()
        {
            stateMachine.Update();
            return IsDead;
        }

        public override string ToString()
        {
            return Entity_Name + ": " + StateMachine.CurrentState.ToString(this);
        }
    }
}
